package com.toy.abash.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.toy.abash.domain.Abash;
import com.toy.abash.domain.UpOrDown;
import com.toy.abash.service.AbashManager;
import com.toy.abash.service.UpOrDownManager;
import com.toy.core.web.BaseController;

@Controller
@RequestMapping("/abash/upordown")
public class UpOrDownController extends BaseController {
	
	@Autowired
	private AbashManager abashManager;
	
	@Autowired
	private UpOrDownManager upOrDownManager;
	
	//保存upordown信息
	@RequestMapping("/save")
	public @ResponseBody String saveUpOrDown(@RequestParam Long postId,
			@RequestParam boolean toUp,@RequestParam boolean toDown,@RequestParam Long operatorId){
		UpOrDown upOrDown = new UpOrDown();
		Abash abash = abashManager.getById(postId);
		upOrDown.setAbashId(postId);
		upOrDown.setToDown(toDown);
		upOrDown.setToUp(toUp);
		upOrDown.setOperatorId(operatorId);
		upOrDown = upOrDownManager.saveUpOrDown(upOrDown);
		abash = abashManager.getById(postId);
		JSONObject result = new JSONObject();
		result.put("message", "aaa");
		result.put("toUpNum", abash.getToUpNum());
		result.put("toDownNum", abash.getToDownNum());
		return result.toJSONString();
	}
}
